#include <iostream>
#include <vector>
#include <map>
#include <climits>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#define pb push_back
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long>>
#define ll long long
using namespace std;
int fact(int n)
{
if (n == 0)
return 1;
int res = 1;
for (int i = 2; i <= n; i++)
res = res * i;
return res;
}
int nCr(int n, int r)
{
return fact(n) / (fact(r) * fact(n - r));
}
bool isValid(int i, int j, int n, int m)
{
if (i >= 0 and i < n and j >= 0 and j < m)
return true;
return false;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
// cout<<"START....\n";
string s;
cin >> s;
int xx[4] = {-1, 1, 0, 0};
int yy[4] = {0, 0, -1, 1};
int n1=s.length();
vvi grid(201, vi(201, 0));
// grid[101][101] = 1;
int i = 101, j = 101;
int f=0;
for (int x = 0; x < s.length(); x++)
{
int sum=0;
grid[i][j]=1;
if (s[x] == 'L')
{
j--;
// grid[i][j] = 1;
}
else if (s[x] == 'R')
{
j++;
// grid[i][j] = 1;
}
else if (s[x] == 'U')
{
i++;
// grid[i][j] = 1;
}
else
{
i--;
// grid[i][j] = 1;
}
if(isValid(i-1,j,201,201)) sum+=grid[i-1][j];
if(isValid(i+1,j,201,201)) sum+=grid[i+1][j];
if(isValid(i,j-1,201,201)) sum+=grid[i][j-1];
if(isValid(i,j+1,201,201)) sum+=grid[i][j+1];
sum+=grid[i][j];
if(sum>1) {f=1; break;}
}
if(f) cout<<"BUG\n"; else cout<<"OK\n";
// grid[i][j] = 1;
// for(int i=0;i<=2*n+4;i++){
// for(int j=0;j<=2*n+4;j++) cout<<grid[i][j]<<" "; cout<<"\n";
// }
// if(ans==s.length()) cout<<"OK\n"; else cout<<"BUG\n";
// if (i == 0 and)
}
1002. Find Common Characters | 1602A - Two Subsequences |
1555A - PizzaForces | 1607B - Odd Grasshopper |
1084A - The Fair Nut and Elevator | 1440B - Sum of Medians |
1032A - Kitchen Utensils | 1501B - Napoleon Cake |
1584B - Coloring Rectangles | 1562B - Scenes From a Memory |
1521A - Nastia and Nearly Good Numbers | 208. Implement Trie |
1605B - Reverse Sort | 1607C - Minimum Extraction |
1604B - XOR Specia-LIS-t | 1606B - Update Files |
1598B - Groups | 1602B - Divine Array |
1594B - Special Numbers | 1614A - Divan and a Store |
2085. Count Common Words With One Occurrence | 2089. Find Target Indices After Sorting Array |
2090. K Radius Subarray Averages | 2091. Removing Minimum and Maximum From Array |
6. Zigzag Conversion | 1612B - Special Permutation |
1481. Least Number of Unique Integers after K Removals | 1035. Uncrossed Lines |
328. Odd Even Linked List | 1219. Path with Maximum Gold |